﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class ucLetters : System.Web.UI.UserControl
{
	string[] letters = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
                     "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
                     "W", "X", "Y", "Z", "All"};


    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
		{
			fill();
		}
    }
	private string format;

	public string Format
	{
		get
		{
			return format;
		}
		set
		{
			format = value;
		}
	}

	protected string Letter
	{
		get
		{
			if (String.IsNullOrEmpty(Request.QueryString["letter"])) 
			{
				return "A";
			}

			return (string)Request.QueryString["letter"];
		}
	}

	protected void fill()
	{
		DataTable dt = new DataTable();
		dt.Columns.Add(new DataColumn("Letter",  typeof(string)));

		for (int i = 0; i < letters.Length; i++)
		{
			DataRow dr = dt.NewRow();
			dr[0] = letters[i];
			dt.Rows.Add(dr);
		}
		rptLetters.DataSource = dt.DefaultView;
		rptLetters.DataBind();

	}
	protected void rptLetters_ItemDataBound(object sender, RepeaterItemEventArgs e)
	{
		HyperLink hl =  (HyperLink) e.Item.FindControl("hlItem");
		DataRowView drv = (DataRowView)e.Item.DataItem;
		string letter = (string)drv.Row["Letter"];

		if(String.Compare(letter, Letter, true) !=0)
			hl.NavigateUrl = string.Format(Format, drv.Row["Letter"]);
	}
}
